//
//  LocationViewController.m
//  欢乐美食
//
//  Created by 遇水 on 15/6/7.
//  Copyright (c) 2015年 遇水. All rights reserved.
//  此处主要是地图定位

#import "LocationViewController.h"
#import <MAMapKit/MAMapKit.h>

#import <AMapSearchKit/AMapSearchAPI.h>
#import "MSDeals.h"
#import "MSBusiness.h"
#import "AnnotationDeal.h"
#import "AnnotationRightButton.h"
#import "historyTool.h"
#import "SingerDealController.h"


#import "CustomAnnotationVew.h"

//自定义大头针库
//#import "hvCustomAnnotation.h"

#define APIKey @"3f51c09a88b208ce41ef5ee43c5f75ea"
@interface LocationViewController ()<MAMapViewDelegate,AMapSearchDelegate>
{
    AMapSearchAPI *_search;
    
    CLLocation *_currentLocation;           //用户当前的位置
    UIButton *_locationButton;              //坐下角的让屏幕返回用户当前定位位置
    
    NSString *_city;                //通过反地理编码获得的用户当前定位的城市
    
}

@property (nonatomic, strong) MAMapView    *mapView;

@property (nonatomic, assign,getter=isDealingDeals) BOOL    dealingDeals;   //标记是否正在请求

@end

@implementation LocationViewController

-(void)viewDidAppear:(BOOL)animated
{
    [self.mapView setZoomLevel:13];

    //设置地图显示当前用户位置为中心
    if (_currentLocation) {
        [self.mapView setCenterCoordinate:_currentLocation.coordinate animated:YES];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [self initMapView];
    [self initSearch];
    [self initControls];
    
    
}


- (void)initMapView
{
    [MAMapServices sharedServices].apiKey = APIKey;
    self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    
    self.mapView.delegate = self;
    self.mapView.compassOrigin = CGPointMake(self.mapView.compassOrigin.x, 22);
    self.mapView.scaleOrigin = CGPointMake(self.mapView.scaleOrigin.x, 22);
    
    
    [self.view addSubview:self.mapView];


    self.mapView.showsUserLocation = YES;
}

//初始化一个搜索服务，此处仅用于反地理编码
- (void)initSearch
{
    _search = [[AMapSearchAPI alloc] initWithSearchKey:APIKey Delegate:self];
}


//初始化locationButton
- (void)initControls
{
    _locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _locationButton.frame = CGRectMake(20, CGRectGetHeight(self.mapView.bounds) - 100, 40, 40);
    _locationButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
    _locationButton.backgroundColor = [UIColor whiteColor];
    _locationButton.layer.cornerRadius = 5;
    
    [_locationButton addTarget:self action:@selector(locateAction) forControlEvents:UIControlEventTouchUpInside];
    
    [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
    
    [self.mapView addSubview:_locationButton];
    
}


#pragma mark - 左下角按钮的点击事件

- (void)locateAction
{

    [self.mapView setCenterCoordinate:_currentLocation.coordinate animated:YES];
    //设置地图跨度
//    [self.mapView setRegion:MACoordinateRegionMake(_currentLocation.coordinate, MACoordinateSpanMake(0.001, 0.001))];
}

//利用服务获得反地理编码
- (void)reGeoAction
{
    if (_currentLocation)
    {
        AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
        
        //传入用户当前的经纬度
        request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
        
        [_search AMapReGoecodeSearch:request];
    }
    
    [self mapView:self.mapView regionDidChangeAnimated:YES];
}

#pragma mark - AMapSearchDelegate
//请求失败回调方法
- (void)searchRequest:(id)request didFailWithError:(NSError *)error
{
     NSLog(@"request :%@, error :%@", request, error);
}

//请求成功回调方法
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
{
    
    NSString *title = response.regeocode.addressComponent.city;
    if (title.length == 0)
    {
        title = response.regeocode.addressComponent.province;
    }
    
    self.mapView.userLocation.title = title;
    self.mapView.userLocation.subtitle = response.regeocode.formattedAddress;

    _city = [title substringToIndex:title.length - 1];      //出去最后的“市”
    
}

#pragma mark - MAMapViewDelegate
//当用户位置改变的时候调用
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated
{
    // 修改定位按钮状态
    if (mode == MAUserTrackingModeNone)
    {
        [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
    }
    else
    {
        [_locationButton setImage:[UIImage imageNamed:@"location_yes"] forState:UIControlStateNormal];
    }
}

- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
    _currentLocation = [userLocation.location copy];
    [self reGeoAction];
}

- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
{

    
}

-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{

    if (![annotation isKindOfClass:[MAPointAnnotation class]]) return nil;


    static NSString *reuseIndetifier = @"annotationReuseIndetifier";
    MAPinAnnotationView *annotationView = (MAPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];

    if (annotationView == nil)
    {
        annotationView=[[MAPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
    }
    annotationView.annotation = annotation;
    annotationView.canShowCallout = YES;
    annotationView.animatesDrop = YES;
    annotationView.draggable = YES;
    annotationView.pinColor = MAPinAnnotationColorPurple;
    annotationView.image = [UIImage imageNamed:@"arrow"];
    return annotationView;

}

//-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(AnnotationDeal *)annotation
//{
//    
//    if (![annotation isKindOfClass:[AnnotationDeal class]]) return nil;
//
//    
//    static NSString *reuseIndetifier = @"annotationReuseIndetifier";
//    MAAnnotationView *annotationView = (MAAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
//        
//    AnnotationRightButton *button = nil;
//    if (annotationView == nil)
//    {
//        annotationView=[[MAAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
//        annotationView.canShowCallout = YES;
//        button = [AnnotationRightButton buttonWithType:UIButtonTypeDetailDisclosure];
//        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//        annotationView.rightCalloutAccessoryView = button;
//
//    }else{
//        button = (AnnotationRightButton *)annotationView.rightCalloutAccessoryView;
//    }
//    annotationView.annotation = annotation;
//    button.deal = annotation.deal;
//    annotationView.image = [UIImage imageNamed:@"arrow"];
//    return annotationView;
//
//}
-(void)buttonClick:(AnnotationRightButton *)button
{
    SingerDealController *singerDeal = [[SingerDealController alloc]init];
    singerDeal.deal = button.deal;
    [self.navigationController pushViewController:singerDeal animated:YES];
}




//当地图滚动(用户变化位置就调用)在此处发送请求
-(void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    if (_city == nil || self.isDealingDeals) {
        return;
    }
    self.dealingDeals = YES;
    //获得当前显示区域的center
    CLLocationCoordinate2D center = mapView.region.center;
    MSFindDealsParam *param = [[MSFindDealsParam alloc]init];
    param.latitude = @(center.latitude);
    param.longitude = @(center.longitude);
    param.radius = @5000;
    param.city = _city;
    
    [MSDealTool findDeals:param success:^(MSFindDealsResult *result) {
        //添加大头针
        [self setdeals:result.deals];
        
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"请求加载失败"];
        self.dealingDeals = NO;
    }];
    
    
}
//在此方法中设置大头针
-(void)setdeals:(NSArray *)deals
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        for (MSDeals *deal in deals) {
            for (MSBusiness *business in deal.businesses) {
                //添加大头针
//                AnnotationDeal *anno = [[AnnotationDeal alloc]init];
//                anno.coordinate = CLLocationCoordinate2DMake(business.latitude, business.longitude);
//                anno.title = deal.title;
//                anno.subtitle = business.address;
//                anno.deal = deal;
                
                MAPointAnnotation *pointAnno = [[MAPointAnnotation alloc] init];
                pointAnno.coordinate = CLLocationCoordinate2DMake(business.latitude, business.longitude);
                pointAnno.title = deal.title;
                pointAnno.subtitle = business.address == nil ? business.name : business.address;
                
                
                //将大头针 对应的模型传入大头针
                if ([self.mapView.annotations containsObject:pointAnno]) {
                    continue;
                }
                
                dispatch_sync(dispatch_get_main_queue(), ^{
                    [self.mapView addAnnotation:pointAnno];
                });
            }
        }
        
        self.dealingDeals = NO;

    });
}


////大头针处理方法了
//-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(AnnotationDeal *)annotation
//{
//    //如果返回的大头针不是自定义的那么久不处理
//    if(![annotation isKindOfClass:[AnnotationDeal class]]) return nil;
//    
//    static NSString *ID = @"AnnotionDeal";
//    AnnotationRightButton *rightButton = nil;
//    MKAnnotationView *annDeal  = [mapView dequeueReusableAnnotationViewWithIdentifier:ID];
//    if (annDeal == nil) {
//        annDeal = [[MKPinAnnotationView alloc]initWithAnnotation:nil reuseIdentifier:ID];
//      
//        //显示标题和子标题
//        annDeal.canShowCallout = YES;
//        //添加右边那个按钮
//        rightButton = [AnnotationRightButton buttonWithType:UIButtonTypeDetailDisclosure];
//        [rightButton addTarget:self action:@selector(clickRithtButton:) forControlEvents:UIControlEventTouchUpInside];
//        annDeal.rightCalloutAccessoryView = rightButton;
//
//    }else
//    {
//        rightButton = (AnnotationRightButton *)annDeal.rightCalloutAccessoryView;
//    }
//    
//    annDeal.annotation = annotation;
//    rightButton.deal = annotation.deal;
//
//    return annDeal;
//}
//
//-(void)clickRithtButton:(AnnotationDeal *)button
//{
//    //跳转到下一个界面
//
//    [[historyTool sharedhistoryTool] saveHistoryDeal:button.deal];
//    SingerDealController *singerVC = [[SingerDealController alloc]init];
//    singerVC.deal = button.deal;
//    [self.navigationController pushViewController:singerVC animated:YES];
//}
//
////用户位置改变调用此方法
//-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
//{
//    
//    CLLocationCoordinate2D center = userLocation.location.coordinate;
//    MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
//    MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
//    
//    //设置地图的显示区域
//    [mapView setRegion:region animated:YES];
//    
//    //获得城市名称
//    [self.geocoder reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray *placemarks, NSError *error) {
//        if (placemarks.count == 0) {
//            return ;
//        }
//        CLPlacemark *placemark = [placemarks firstObject];
////
//        self.locationCity = placemark.locality;
////        NSString *city = placemark.addressDictionary[@"State"];   //获得内部的地址
////        
//        //获得城市
////        self.locationCity = [city substringFromIndex:city.length - 1];
//
//        //定位到城市就发送请求
//        [self mapView:self.mapView regionDidChangeAnimated:YES];
//        
//    }];
//
//    
//}
//
////用户地区改变就调用这个方法了
//-(void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
//{
////    if (self.locationCity == nil || self.i) return;
//    //在这个方法中发送请求数据
//    MSFindDealsParam *param = [[MSFindDealsParam alloc]init];
//    
//    CLLocationCoordinate2D center = mapView.region.center;
//    
//    param.latitude= @(center.latitude);
//    param.longitude =@(center.longitude) ;
//    if(self.locationCity == nil){
//        param.city = @"北京";
//    }
//    param.city =self.locationCity ;
//    param.keyword = @"美食";
//    param.radius = @5000;
//    
//    //发送请求
//    [MSDealTool findDeals:param success:^(MSFindDealsResult *result) {
//        //请求结果
//        [self useDeals:result.deals];
//    } failure:^(NSError *error) {
//        [MBProgressHUD showError:@"加载团购失败，请稍后再试"];
//        
//        self.loadingDeal = NO;
//        
//    }];
//    
//}
//
//
////处理团购信息
//-(void)useDeals:(NSArray *)deals
//{
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        for (MSDeals *deal in deals) {
//            for (MSBusiness *business in deal.businesses) {
//                AnnotationDeal *anno = [[AnnotationDeal alloc] init];
//                anno.coordinate = CLLocationCoordinate2DMake(business.latitude, business.longitude);
//                anno.title = deal.title;
//                anno.subtitle = business.name;
//                // 设置大头针对应的团购模型
//                anno.deal = deal;
//                
//                // 说明这个大头针已经存在这个数组中（已经显示过了）
//                if ([self.mapView.annotations containsObject:anno]) continue;
//                
//                dispatch_sync(dispatch_get_main_queue(), ^{
//                    [self.mapView addAnnotation:anno];
//                });
//            }
//        }
//        
//        self.loadingDeal = NO;
//    });
//
//}
//



@end


//{
//    MAMapView *self.mapView;
//    UIButton *_locationButton;          //定位按钮(用来修改定位模式)
//    AMapSearchAPI *_search;
//    
//    CLLocation *_currentLocation;
//    
//    UITableView *_tableView;
//    NSArray *_pois;
//    
//    NSMutableArray *_annotations;
//    
//}

//
//-(void)initSearch
//{
//    _search = [[AMapSearchAPI alloc]initWithSearchKey:APIKey Delegate:self];
//}
//
//
//-(void)setMapView{
//    //允许用户定位
//    self.mapView.showsUserLocation = YES;
//    //显示实时路况
//    //    self.mapView.showTraffic = YES;
//    
//    //设置定位模式
//    self.mapView.userTrackingMode = MAUserTrackingModeNone;
//    //实时在后台记录用户位置
//    //    self.mapView.pausesLocationUpdatesAutomatically = NO;
//    
//    
//}
//
//
//- (void)initAttributes
//{
//    _annotations = [NSMutableArray array];
//    _pois = nil;
//}
//
////初始化地图
//-(void)initMapView{
//    [MAMapServices sharedServices].apiKey = APIKey;
//    
//    self.mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) *0.5)];
//    self.mapView.delegate = self;
//    self.mapView.scaleOrigin = CGPointMake(self.mapView.scaleOrigin.x, 22);
//    self.mapView.compassOrigin = CGPointMake(self.mapView.compassOrigin.x, 22);
//
//    self.mapView.showsUserLocation = YES;
//    [self.view addSubview:self.mapView];
//    
//}
//
////初始化表格
//- (void)initTableView
//{
//    CGFloat halfHeight = CGRectGetHeight(self.view.bounds) * 0.5;
//    
//    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, halfHeight, CGRectGetWidth(self.view.bounds), halfHeight) style:UITableViewStylePlain];
//    _tableView.delegate = self;
//    _tableView.dataSource = self;
//    
//    [self.view addSubview:_tableView];
//}
//
//
//
//
//#pragma mark - 搜索事件
//- (void)searchAction
//{
//    if (_currentLocation == nil || _search == nil)
//    {
//        NSLog(@"search failed");
//        return;
//    }
//    
//    AMapPlaceSearchRequest *request = [[AMapPlaceSearchRequest alloc] init];
//    request.searchType = AMapSearchType_PlaceAround;
//    request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
//    
//    request.keywords = @"餐饮";
//    
//    [_search AMapPlaceSearch:request];
//}
//
//
//
///**
// *  初始化定位按钮
// */
//-(void)initLocationButton{
//    _locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    _locationButton.frame = CGRectMake(20, CGRectGetHeight(self.mapView.bounds) - 90, 40, 40);
//    _locationButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleRightMargin;
//    _locationButton.layer.cornerRadius = 5;
//    _locationButton.backgroundColor = [UIColor whiteColor];
//    [_locationButton addTarget:self action:@selector(ClickLocatonButton) forControlEvents:UIControlEventTouchUpInside];
//    [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
//    [self.mapView addSubview:_locationButton];
//}
//
///**
// *  修改定位模式
// */
//-(void)ClickLocatonButton{
//    if(self.mapView.userTrackingMode == MAUserTrackingModeNone){
//        [self.mapView setUserTrackingMode:MAUserTrackingModeFollowWithHeading animated:YES];
//    }else{
//        [self.mapView setUserTrackingMode:MAUserTrackingModeNone animated:YES];
//    }
//}
//
//#pragma mark - MAMapViewDelegate
///**
// *  用户的位置改变时调用这个方法
// *
// *  @param mapView          地图对象
// *  @param userLocation
// *  @param updatingLocation 改变后的
// */
//-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
//    
//    //获得用户当前的位置信息
////    MSLog(@"-userLocation---%@", userLocation.location.coordinate);
//    int latitude = userLocation.location.coordinate.latitude; //得到float型 8位变成了 6 位
//    CLLocationDegrees latitud = userLocation.location.coordinate.latitude;
//    float  longitude = userLocation.location.coordinate.longitude;
//    
//    if([[NSUserDefaults standardUserDefaults]doubleForKey:@"longitude"]!= longitude){
//        //将数据存储到系统偏好中
//        NSUserDefaults *defaults =  [NSUserDefaults standardUserDefaults];
//        [defaults setFloat:latitude forKey:@"latitude"];
//        [defaults setFloat:longitude forKey:@"longitude"];
//        [defaults synchronize];
//       
//    }
//}
//
//
//- (void)reGeoAction
//{
//    if (_currentLocation)
//    {
//        AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
//        
//        request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
//        
//        [_search AMapReGoecodeSearch:request];
//    }
//}
//
//- (void)searchRequest:(id)request didFailWithError:(NSError *)error
//{
//    NSLog(@"request :%@, error :%@", request, error);
//}
//
//
//- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
//{
//    NSLog(@"response :%@", response);
//    
//    NSString *title = response.regeocode.addressComponent.city;
//    if (title.length == 0)
//    {
//        // 直辖市的city为空，取province
//        title = response.regeocode.addressComponent.province;
//    }
//    
//    // 更新我的位置title
//    self.mapView.userLocation.title = title;
//    self.mapView.userLocation.subtitle = response.regeocode.formattedAddress;
//}
//
//
//- (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
//{
//    NSLog(@"request: %@", request);
//    NSLog(@"response: %@", response);
//    
//    if (response.pois.count > 0)
//    {
//        _pois = response.pois;
//        
//        [_tableView reloadData];
//        
//        // 清空标注
//        [self.mapView removeAnnotations:_annotations];
//        [_annotations removeAllObjects];
//    }
//}
//
//
//- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
//{
//    // 选中定位annotation的时候进行逆地理编码查询
//    if ([view.annotation isKindOfClass:[MAUserLocation class]])
//    {
//        [self reGeoAction];
//    }
//}
//- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
//{
//    if ([annotation isKindOfClass:[MAPointAnnotation class]])
//    {
//        static NSString *reuseIndetifier = @"annotationReuseIndetifier";
//        MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
//        if (annotationView == nil)
//        {
//            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
//        }
//        annotationView.canShowCallout = YES;
//        
//        return annotationView;
//    }
//    
//    return nil;
//}
///**
// *  定位模式改变，
// *
// */
//-(void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
//    
//    if(mode == MAUserTrackingModeNone){
//        //普通模式
//        [_locationButton setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
//    }else{
//        [_locationButton setImage:[UIImage imageNamed:@"location_yes"] forState:UIControlStateNormal];
//    }
//}
//
//#pragma mark - 表格的数据
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    static NSString *cellIdentifier = @"cellIdentifier";
//    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//    
//    if (cell == nil)
//    {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
//    }
//    
//    AMapPOI *poi = _pois[indexPath.row];
//    
//    cell.textLabel.text = poi.name;
//    cell.detailTextLabel.text = poi.address;
//    
//    return cell;
//    
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    return _pois.count;
//}
//
//#pragma mark - UITableViewDelegate
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    
//    // 为点击的poi点添加标注
//    AMapPOI *poi = _pois[indexPath.row];
//    
//    MAPointAnnotation *annotation = [[MAPointAnnotation alloc] init];
//    annotation.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude);
//    annotation.title = poi.name;
//    annotation.subtitle = poi.address;
//    
//    [self.mapView addAnnotation:annotation];
//    
//    [_annotations addObject:annotation];
//}
//
